//
//  GNMainController.swift
//  SinaWeChat
//
//  Created by mac on 15/12/5.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit
import SVProgressHUD
class GNMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        let tabBar = GNTabBar()
        
        tabBar.composeButtonClosure = {
            
            [weak self] in
            if !GNUserAccountViewModel.sharedAccount.userLogon {
                SVProgressHUD.showErrorWithStatus("请先登录")
                return
            }
            
            // 初始化 composeView
            let composeView = GNComposeView()
            composeView.show(self)
            
        }
        
        setValue(tabBar, forKeyPath:"tabBar")
        
        addChildViewController(GNHomeViewController(), imgName:"tabbar_home" , title: "首页")
        addChildViewController(GNMessageViewController(), imgName:"tabbar_message_center", title: "消息")
        addChildViewController(GNDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(GNProfileViewController(), imgName: "tabbar_profile", title: "我")
        
        //5秒之后销毁
        
        //self.performSelector("dismiss", withObject: nil, afterDelay: 5)
        
    }
    
    
    
    
    
    

    
    //添加子控制器
    func addChildViewController(childController: UIViewController,imgName:String,title:String) {
        
        
        //设置文字
        childController.title = title
        
        //设置图片
        childController.tabBarItem.image = UIImage(named: imgName)
        
        //渲染图片以原样显示
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置tabbar title颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        
        //添加子控制器
        
        addChildViewController(GNNavController(rootViewController: childController))
        
        
        
    }
    


}
